import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: "/",
        name: "App",
        component: () => import("@/views/Map")
    },
    {
        path: "/map",
        name: "map",
        component: () => import("@/views/Map")
    },
	{
		path: "/center",
		name: "center",
		component: () => import("@/views/Center")
	},
	{
		path: "/order",
		name: "order",
		component: () => import("@/views/Order")
	},
	{
		path: "/carportDetail:carportId",
		name: "carportDetail",
		component: () => import("@/views/CarportDetail")
	},
	{
		path: "/accuse/:orderId/:accuseStatus",
		name: "accuse",
		component: () => import("@/views/Accuse")
	},
	{
		path: "/pay:money:orderId/:payoffId",
		name: "pay",
		component: () => import("@/views/Pay")
	},
	{
		path: "/payoff:orderId",
		name: "payoff",
		component: () => import("@/views/Payoff")
	},
	{
		path: "/aliPay:orderId/:money/:payoffId",
		name: "aliPay",
		component: () => import("@/views/AliPay")
	},
	{
		path: "/login",
		name: "Login",
		component: function() {
			return import("../views/Login.vue")
		}
	},
	{
		path: "/register",
		name: "Register",
		component: function() {
			return import("../views/Register.vue")
		}
	},
    {
        path: "/carportInfo/:rentalCarportId",
        name: "carportInfo",
        component: () => import("@/views/CarportInfo")
    }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
// 路由守卫
router.beforeEach((to,from,next)=>{
	console.log(to);
	if(to.path==="/login"||to.path==="/register"||to.path==="/map"||to.path==="/"){
		next();
	}else{
		if(sessionStorage.getItem("Access-Token")){
			next();
		}else{
			next("/login");
		}
	}
});
export default router
